<template>
  <el-dialog 
    title="新建项目"
    top="50px"
     width="80%"
    custom-class="sa-common-dialog"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false">
    <div class="sa-dialog-body">
      <ProjInfoForm ref="projAddForm"/>
    </div>
    <span slot="footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import ProjInfoForm from './ProjInfoForm'

export default {
  name: 'ProjAddDialog',
  components: {
    ProjInfoForm
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    addForm () {
      return this.$refs.projAddForm
    }
  },
  watch: {
    visible: {
      handler (value, oldValue) {
        if (value) {
          this.handleCalcSize()
          this.handleReset()
        }
      }
    }
  },
  methods: {
    handleCalcSize () {
      console.log('handleCalcSize')
    },
    handleClose () {
      console.log('handleClose')
      this.$emit('close')
    },
    handleSubmit () {
      const { addForm } = this
      const valid = addForm.validateForm()
      if (valid) {
        const formData = addForm.getFormData()
        console.log("addFormData", formData)
        this.$emit('success', formData)
      }
    },
    handleReset () {
      this.$nextTick(() => {
        this.addForm.resetForm()
      })
    }
  },
}
</script>

<style lang="scss" scoped>

</style>